package com.dbq.fast.common.net;


import com.dbq.fast.business.coupons.bean.CouponsData;
import com.dbq.fast.business.coupons.bean.Page;
import com.dbq.fast.business.invite.been.InviteInfo;
import com.dbq.fast.business.invite.been.ShareIntroduce;
import com.dbq.fast.business.login.bean.CustomProfile;
import com.dbq.fast.business.login.bean.TokenInfo;
import com.dbq.fast.business.login.bean.WbUserInfo;
import com.dbq.fast.business.login.bean.WeChatProfile;
import com.dbq.fast.business.login.bean.WeChatToken;
import com.dbq.fast.business.main.bean.AdReward;
import com.dbq.fast.business.main.bean.ProxyDomain;
import com.dbq.fast.business.main.bean.SubscriptionMeal;
import com.dbq.fast.business.main.bean.VpnNode;
import com.dbq.fast.business.main.bean.VpnState;
import com.dbq.fast.business.me.bean.ActiveMoney;
import com.dbq.fast.business.me.bean.InviteFriendsInfoBean;
import com.dbq.fast.business.me.bean.InviteFriendssSubmitBean;
import com.dbq.fast.business.me.bean.RewardInfo;
import com.dbq.fast.business.me.bean.VersionBean;
import com.dbq.fast.business.me.bean.WithdrawInfo;
import com.dbq.fast.business.order.bean.OrderInfo;
import com.dbq.fast.business.product.bean.DoUserDiscount;
import com.dbq.fast.business.product.bean.ProductType;
import com.dbq.fast.business.product.bean.ServiceType;
import com.dbq.fast.business.product.bean.WalletAddress;
import com.dbq.fast.business.ypage.YPageBean;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;

import io.reactivex.Flowable;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Query;
import retrofit2.http.Streaming;
import retrofit2.http.Url;

/**
 * Created by marks on 2016/8/5.
 */
public interface HttpService {

    //微信--获取WeChat的access_token
    //"/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code"
    @GET("/sns/oauth2/access_token")
    Flowable<WeChatToken> getWCToken(@Query("appid") String appid,
                                     @Query("secret") String secret,
                                     @Query("code") String code,
                                     @Query("grant_type") String grant_type);

    //微信--获取WeChat的access_token
    //"/sns/userinfo?access_token=%s&openid=%s"
    @GET("/sns/userinfo")
    Flowable<WeChatProfile> getWCProfile(@Query("access_token") String access_token,
                                         @Query("openid") String openid);

    //获取服务器端返回的用户登录信息——新接口
    @Headers("pkgName:com.unicorn.china")
    @POST("/user/oauthLogin")
    Flowable<HttpResult<CustomProfile>> getUserInfo(@Header("verCode") int verCode, @Header("vid") String vid, @Body RequestBody body);

    //获取最近十个订单
    @POST("/order/showOrder")
    Flowable<HttpResult<OrderInfo>> getOrderList(@Header("language") String language, @Header("authorization") String token, @Body RequestBody body);

    //退出登录
    @DELETE("/user/logout")
    Flowable<String> logOut(@Header("authorization") String token);

    //刷新token——新接口
    @GET("/tokens/refreshToken")
    Flowable<HttpResult<TokenInfo>> refreshToken(@Query("refreshToken") String refreshToken);

    //刷新token(同步方式)——新接口
    @GET("/tokens/refreshToken")
    Call<HttpResult<TokenInfo>> refreshTokenSync(@Query("refreshToken") String refreshToken);

    //获取 vpn 节点
    @Headers("pkgName:com.unicorn.pro")
    @POST("/vpn/queryvpn")
    Call<HttpResult<VpnNode>> getVpnConfig(@Header("verCode") int verCode, @Header("language") String language, @Header("authorization") String token, @Query("account") String account, @Query("ostype") int osType, @Query("timeout") boolean timeout);

    //查询套餐信息
    @Headers("pkgName:com.unicorn.pro")
    @POST("/serve/querysetmeal")
    Call<HttpResult<VpnNode>> querySetMeal(@Header("verCode") int verCode, @Header("language") String language, @Header("authorization") String token, @Query("account") String account, @Query("ostype") int osType);

    //获取VIP 套餐类型
    @GET("/serve/show")
    Flowable<HttpResult<ServiceType>> getVipService(@Header("language") String language, @Header("authorization") String token, @Query("account") String account);

    //获取产品的详细数据
    @Headers("Content-type:application/json;charset=UTF-8")
    @POST("/serve/setmeal/show")
    Flowable<HttpResult<ProductType>> getProduct(@Header("authorization") String token, @Body HashMap<String, Object> body);

    //上报 vpn 状态
    @GET("/vpn/sendvpnstatus")
    Call<HttpResult<VpnState>> uploadVpnState(@Header("authorization") String token, @Query("account") String account);
//
//    //获取阿里支付的预支付订单信息
//    @Headers("Content-type:application/json;charset=UTF-8")
//    @POST("/pay/alipay")
//    Flowable<HttpResult<AliPayOrderInfo>> getAliOrderInfo(@Header("authorization") String token, @Body HashMap body);
//
//    //获取阿里支付的预支付订单信息
//    @Headers("Content-type:application/json;charset=UTF-8")
//    @POST("/weixin/wxPrePay")
//    Flowable<HttpResult<WxPayOrderInfo>> getWxOrderInfo(@Header("authorization") String token, @Body HashMap body);

    //拆分在请求VPNNode节点中，proxy_domain属性为独立的接口
    @Headers("Content-type:application/json;charset=UTF-8")
    @GET("/vpn/getproxydomain")
    Flowable<HttpResult<ProxyDomain>> getProxyDomain(@Header("authorization") String token);

    @Multipart
    @POST("/logUpload")
    Flowable<HttpResult> logUpload(@Part("uId") String uId, @Part("problem") String problem, @Part("contactInfo") String contactInfo, @Part("vpnId") String vpnId, @Part("appName") String appName, @Part("version") String version);

    @Multipart
    @POST("/logUpload")
    Flowable<HttpResult> logUpload(@Part() List<MultipartBody.Part> files, @Part("uId") String uId, @Part("problem") String problem, @Part("contactInfo") String contactInfo, @Part("vpnId") String vpnId, @Part("appName") String appName, @Part("version") String version);

    // 接口改成下面的了
    // 上传firebase的token
//    @POST("/push/getToken")
//    Call<HttpResult<JSONObject>> uploadFirebaseToken(@Header("authorization") String token, @Body HashMap<String, String> body);

    // 上传firebase的token  兼容ios
    @POST("/push/receiveToken")
    Call<HttpResult<JSONObject>> uploadFirebaseToken(@Header("authorization") String token, @Body HashMap<String, String> body);

    //根据用户ID获取用户信息 http://open.weibo.com/wiki/2/users/show
    @GET("/2/users/show.json")
    Flowable<WbUserInfo> accessWbProfile(@Query("access_token") String token, @Query("uid") String uid);

    /**
     * 获取优惠卡券
     *
     * @param token
     * @param page
     * @return
     */
    @Headers("Content-type:application/json;charset=UTF-8")
    @POST("/discount/showUserDiscount")
    Flowable<HttpResult<CouponsData>> getCoupons(@Header("authorization") String token, @Body Page page);

    /**
     * 选择卡券后该显示的价格
     *
     * @param token
     * @param page
     * @return
     */
    @Headers("Content-type:application/json;charset=UTF-8")
    @POST("/discount/doUserDiscount")
    Flowable<HttpResult<DoUserDiscount>> getAfterCoupons(@Header("authorization") String token, @Body HashMap page);

    /**
     * 分享模块
     *
     * @param token
     * @return
     */
    @Headers("Content-type:application/json;charset=UTF-8")
    @POST("/discount/showInviteFriendsInfo")
    Flowable<HttpResult<InviteFriendsInfoBean>> getInviteFriendsInfo(@Header("authorization") String token);

    /**
     * 分享模块--提交用户邀请码
     *
     * @param vpnId
     * @return
     */
    @Headers("Content-type:application/json;charset=UTF-8")
    @POST("/discount/doInviteFriends")
    Flowable<HttpResult<InviteFriendssSubmitBean>> doInviteFriends(@Header("authorization") String token, @Body HashMap vpnId);


    /**
     * 提交google购买成功后，订单提交到服务器
     *
     * @param token
     * @param page
     * @return
     */
    @Headers("Content-type:application/json;charset=UTF-8")
    @POST("/pay/googleplay")
    Flowable<HttpResult<DoUserDiscount>> submitOrder(@Header("authorization") String token, @Body HashMap page);

    //VPN 延迟上报
    @Headers("Content-type:application/json;charset=UTF-8")
    @POST("/vpn/netspeed")
    Flowable<HttpResult> uploadVPNTimeDelay(@Header("authorization") String token, @Body HashMap body);

    //评分
    @POST("/monitor/addAdvise")
    Flowable<String> uploadComment(@Body HashMap comment);

    //查询24h内是否奖励过
    @POST("/vpn/queryReward")
    Flowable<HttpResult<AdReward>> queryReward(@Header("authorization") String token, @Query("account") String account);

    //上报广告奖励
    @POST("/vpn/addReward")
    Flowable<String> addReward(@Header("authorization") String token, @Query("account") String account);

    //stripe 支付
    @POST("/strip/alipay")
    Flowable<HttpResult> stripPay(@Header("authorization") String token, @Body HashMap body);

    @GET("/pay/w")
    Flowable<HttpResult<WalletAddress>> getWalletAddr();

    @Headers("Content-type:application/json;charset=UTF-8")
    @POST("/payment/info")
    Flowable<HttpResult> paymentInfo(@Body HashMap body);

    @Headers("Content-type:application/json;charset=UTF-8")
    @POST("/save/event")
    Flowable<HttpResult> saveEvent(@Body HashMap body);

    @GET("/serve/activity/rushpurchase")
    Flowable<HttpResult<SubscriptionMeal>> querySubscriptionMeal();

    @Headers("Content-type:application/json;charset=UTF-8")
    @POST("/pay/subscriptions")
    Flowable<HttpResult<DoUserDiscount>> submitSubsOrder(@Header("authorization") String token, @Body HashMap body);

    // 获取金额及可提现状态
    @GET("/activity/withdraw/show")
    Flowable<HttpResult<ActiveMoney>> queryActiveMoney(@Header("authorization") String token, @Query("vid") String vpnId);

    // 奖励列表接口
    @POST("/activity/invite/charge/show")
    Flowable<HttpResult<RewardInfo>> queryRewardInfo(@Header("authorization") String token, @Body HashMap hashMap);

    // 提现列表
    @POST("/activity/withdraw/list/show")
    Flowable<HttpResult<WithdrawInfo>> queryWithdrawInfo(@Header("authorization") String token, @Body HashMap hashMap);

    // 绑定微信
    @POST("/activity/wechat")
    Flowable<HttpResult> bindWx(@Header("authorization") String token, @Body HashMap body);

    // 提现
    @POST("/activity/withdraw/do")
    Flowable<HttpResult> withdraw(@Header("authorization") String token, @Body HashMap body);

    // 邀请活动分享链接生成
    @POST("/activity/invite/share")
    Flowable<HttpResult<InviteInfo>> shareLinkInfo(@Header("authorization") String token, @Body HashMap body);

    @GET("/activity/introduce")
    Flowable<HttpResult<ShareIntroduce>> shareRuleIntroduce(@Query("moduleId") String moduleId);

    // 奖励列表接口
    @POST("/video/show")
    Flowable<HttpResult<YPageBean>> queryYData(@Header("authorization") String token, @Body HashMap hashMap);

    @GET("/activity/version/check")
    Flowable<HttpResult<VersionBean>> checkVersion(@Header("authorization") String auth, @Query("vpnId") String vpnId, @Query("version") String version);

    @Streaming
    @GET
    Flowable<ResponseBody> downloadApk(@Url String apkUrl);

    // 获取手机验证码
    @GET("/subscriber/phone/captcha")
    Flowable<HttpResult> requestVerifiCode(@Query("phoneNum") String phone);

    // 重置密码获取验证码
    @GET("/subscriber/phone/pwd/captcha")
    Flowable<HttpResult> requestPwdVerifiCode(@Query("account") String phone);

    // 校验验证码
    @POST("/subscriber/phone/captcha/check")
    Flowable<HttpResult> checkVerifiCode(@Body HashMap hashMap);

    // 注册
    @Headers("pkgName:com.unicorn.china")
    @POST("/subscriber/phone/register")
    Flowable<HttpResult<CustomProfile>> register(@Header("verCode") int verCode, @Header("vid") String vid, @Body RequestBody body);

    // 登录
    @Headers("pkgName:com.unicorn.china")
    @POST("/subscriber/login")
    Flowable<HttpResult<CustomProfile>> login(@Header("verCode") int verCode, @Header("vid") String vid, @Body RequestBody body);

    // 重置密码
    @POST("/subscriber/phone/pwd/reset")
    Flowable<HttpResult> resetPwd(@Body HashMap body);

    // 退出登录
    @DELETE("/subscriber/logout")
    Flowable<HttpResult> newLogOut(@Header("authorization") String token);

    //获取邮箱验证码
    @GET("/subscriber/email/captcha")
    Flowable<HttpResult> requestEmailVerifiCode(@Header("authorization") String auth, @Query("email") String email,@Query("account") String account);

    //绑定邮箱
    @POST("subscriber/email/binding")
    Flowable<HttpResult> bindEmail(@Header("authorization") String auth,@Body HashMap hashMap);
}